﻿package mortal.game.view.vip.panel
{
    import baseEngine.modifiers.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    import com.mui.controls.*;
    import flash.display.*;
    import flash.geom.*;
    import frEngine.effectEditTool.temple.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.scene3D.player.entity.*;

    public class Model3dBasePanel extends GSprite
    {
        protected var _rect3d:Rect3DObject;
        protected var _roleModelPlayer:UserModelPlayer;
        protected var _actionPlayer:ActionPlayer;
        protected var _effectPlayer:EffectPlayer;
        protected var _img2dList:Array;
        protected var _isAddAction:Boolean;
        private var turnNum:Number = 0;
        private var tween:TweenMax;

        public function Model3dBasePanel()
        {
            this._img2dList = [];
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this.tween && this.tween.active)
            {
                this.tween.kill();
            }
            this.remove3d();
            this._isAddAction = false;
            this._rect3d = null;
            this._img2dList.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        private function modelTurn() : void
        {
            if (this._actionPlayer && this._isAddAction)
            {
                this._actionPlayer.y = this._actionPlayer.y + Math.cos(this.turnNum) * 0.8;
                this._actionPlayer.rotationY = this._actionPlayer.rotationY + 2;
            }
            this.turnNum = this.turnNum + 0.05;
            return;
        }// end function

        public function remove3d() : void
        {
            var _loc_1:Img2D = null;
            if (this._rect3d)
            {
                if (this._roleModelPlayer)
                {
                    this._rect3d.disposeObj3d(this._roleModelPlayer);
                    this._roleModelPlayer = null;
                }
                if (this._actionPlayer)
                {
                    this._rect3d.disposeObj3d(this._actionPlayer);
                    this._actionPlayer = null;
                }
                if (this._effectPlayer)
                {
                    this._rect3d.disposeObj3d(this._effectPlayer);
                    this._effectPlayer = null;
                }
            }
            for each (_loc_1 in this._img2dList)
            {
                
                _loc_1.dispose();
            }
            this._img2dList.length = 0;
            return;
        }// end function

        public function set rect3d(param1:Rect3DObject) : void
        {
            this._rect3d = param1;
            return;
        }// end function

        public function get rect3d() : Rect3DObject
        {
            return this._rect3d;
        }// end function

        public function addRoleModel(param1:int, param2:int, param3:int, param4:int, param5:int, param6:int, param7:int, param8:int, param9:int, param10:Number, param11:int = 0, param12:int = 0) : void
        {
            if (this._roleModelPlayer == null)
            {
                this._roleModelPlayer = FrObjectPool.getObject(UserModelPlayer, this);
            }
            this._roleModelPlayer = FrObjectPool.getObject(UserModelPlayer, this);
            this._roleModelPlayer.updateIsShowEffect(true, true, true);
            this._roleModelPlayer.updateInfo(param1, param2, param3, param4, param5, param6, param7, false);
            this._roleModelPlayer.scaleAll = param10;
            this._roleModelPlayer.rotationX = param11;
            this._roleModelPlayer.rotationY = param12;
            this._roleModelPlayer.useLight();
            this._roleModelPlayer.setRenderList(this._rect3d.renderList);
            if (this._rect3d)
            {
                this._rect3d.addObject3d(this._roleModelPlayer, param8, param9);
            }
            return;
        }// end function

        public function addActionModel(param1:String, param2:String, param3:String, param4:int, param5:int, param6:int, param7:int, param8:int, param9:String, param10:Boolean = false) : void
        {
            if (this._actionPlayer == null)
            {
                this._actionPlayer = FrObjectPool.getObject(ActionPlayer, this);
            }
            this._actionPlayer.load(param1, param2, param3);
            this._actionPlayer.changeAction(param9);
            this._actionPlayer.play();
            this._actionPlayer.rotationZ = param8;
            this._actionPlayer.rotationY = param7;
            var _loc_11:* = param6;
            this._actionPlayer.scaleZ = param6;
            var _loc_11:* = _loc_11;
            this._actionPlayer.scaleY = _loc_11;
            this._actionPlayer.scaleX = _loc_11;
            if (this._rect3d)
            {
                this._rect3d.addObject3d(this._actionPlayer, param4, param5);
            }
            this._isAddAction = param10;
            if (this._isAddAction)
            {
                this.tween = TweenMax.to(this._actionPlayer, 0.01, {ease:Quint.easeIn, repeat:-1, onRepeat:this.modelTurn});
            }
            return;
        }// end function

        public function addSelfEffect(param1:String) : void
        {
            this._effectPlayer = EffectPlayerPool.instance.getEffectPlayer(param1, this._actionPlayer, this._rect3d.renderList, false);
            this._effectPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
            if (this._effectPlayer.temple is TempleRole)
            {
                (this._effectPlayer.temple as TempleRole).setRoleParams(this._actionPlayer, null, null);
            }
            this._effectPlayer.resetTimerContorler(this._actionPlayer.timerContorler);
            return;
        }// end function

        public function addEffect(param1:String, param2:int, param3:int, param4:int) : void
        {
            if (this._effectPlayer == null)
            {
                this._effectPlayer = EffectPlayerPool.instance.getEffectPlayer(param1, null, this._rect3d.renderList, false);
            }
            this._effectPlayer.play();
            var _loc_5:* = param4;
            this._effectPlayer.scaleZ = param4;
            var _loc_5:* = _loc_5;
            this._effectPlayer.scaleY = _loc_5;
            this._effectPlayer.scaleX = _loc_5;
            this._rect3d.addObject3d(this._effectPlayer, param2, param3);
            return;
        }// end function

        public function addImg2d(param1:BitmapData, param2:Rectangle, param3:int = 50) : void
        {
            var _loc_4:BitmapData = null;
            var _loc_5:Img2D = null;
            if (this._rect3d)
            {
                _loc_4 = param1;
                _loc_5 = new Img2D(null, _loc_4, param2, false);
                this._rect3d.addImg(_loc_5, param3);
                this._img2dList.push(_loc_5);
            }
            return;
        }// end function

    }
}
